<?php ob_start();?>
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
	include($root.'/standart/head.php');
 	include($root.'/standart/dateHeader.php');
 	include($root.'/standart/dbconnect.php');
 	$db = connect();
 	
$bgn_date = "";
$end_date = "";
$tmpDate = $_GET["begin_date"];
if($tmpDate <> ""){
	list($gun,$ay,$yil) = explode('.',$tmpDate);
	$bgn_date = $yil.'-'.$ay.'-'.$gun;
}
$tmpDate = $_GET["end_date"];
if($tmpDate <> ""){
	list($gun,$ay,$yil) = explode('.',$tmpDate);
	$end_date = $yil.'-'.$ay.'-'.$gun;
}
	
	$userId = $_GET ["user_id"];
	$stmt = "SELECT ORDERS.ID,GEVEZE_USER.NAME,GEVEZE_USER.SURNAME,ORDERS.ORDER_DATE,
	ORDERS.PAYMENT_TYPE,ADDRESS.ADDRESS_1,ORDERS.NOTES,ORDERS.TOTAL_AMOUNT FROM ORDERS
	LEFT OUTER JOIN GEVEZE_USER ON
	ORDERS.USER_ID=GEVEZE_USER.ID
	LEFT OUTER JOIN ADDRESS ON
	ORDERS.SHIPPING_ADDRESS=ADDRESS.ID
	WHERE ORDERS.CANCEL = 0";
	if ($bgn_date != "") {
		$stmt = $stmt . " AND ORDER_DATE > '$bgn_date'";
	}
	if ($end_date != "") {
		$stmt = $stmt . " AND ORDER_DATE < '$end_date'";
	}
	if ($userId != "") {
		$stmt = $stmt . " AND GEVEZE_USER.ID = '$userId'";
	}
	$stmt = $stmt . " ORDER BY ORDER_DATE DESC";
	$res = $db->query ( $stmt ) or die ( $stmt . "<br/><br/>" . mysql_error () );
?>
<table class="table table-striped table-bordered table-hover"
	id="dataTables-example">
	<thead>
		<tr>
			<th>Sipariş No</th>
			<th>İsim</th>
			<th>Soyisim</th>
			<th>Sipariş Tarihi</th>
			<th>Ödeme Tipi</th>
			<th style="display: none;">Gönderim Adresi</th>
			<th>Sipariş Notu</th>
			<th>Sipariş Tutarı</th>
		</tr>
	</thead>
	<tbody>
        <?php $odd = true; ?>
        <?php $grandTotal = 0.00?>
       	<?php while($row = $res->fetch_assoc()){?>
        	<tr class="<?php echo $odd ? "odd" : "even";?> "
			style="cursor: pointer;">
			<td><?php echo $row["ID"];?></td>
			<td><?php echo $row["NAME"];?></td>
			<td><?php echo $row["SURNAME"];?></td>
			<td><?php echo date("d/m/Y H:i",strtotime($row["ORDER_DATE"]));?></td>
			<td><?php echo $row["PAYMENT_TYPE"];?></td>
			<td style="display: none;"><?php echo $row["ADDRESS_1"];?></td>
			<td><?php echo $row["NOTES"];?></td>
			<td style="text-align: right;"><?php echo $row["TOTAL_AMOUNT"]; ECHO ' TL';?></td>
		</tr>
			<?php $odd = !$odd;?>
			<?php $grandTotal += $row["TOTAL_AMOUNT"] ?>
		<?php }?>
		<?php if(isset($_GET['report'])){?>
			
		
	<tfoot>
		<tr>
			<td style="display: none;"></td>
			<td style="display: none;"></td>
			<td style="display: none;"></td>
			<th colspan="6" style="text-align: right">Toplam:</th>
			<th style="text-align: right;"><?php echo number_format($grandTotal,2); ECHO ' TL'?></th>
		</tr>
	</tfoot>
		<?php }?>
		</tbody>
</table>
<?php
$res->close ();
disconnect ( $db );
?>
<?php ob_end_flush(); ?>